home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Design
/
WB Collection.iso
/
workbench werkzeuge
/
palette tools
/
wcc
/
wcc4.mod
< prev
next >
Wrap
Text File
|
1996-04-07
|
23KB
|
925 lines
MODULE WCC4;
(*
WCC 4.0 (29.4.1993)
by Carsten Orthbandt
Compiler: Amiga Oberon 3.1
*)
IMPORT
e: Exec,
es: ExecSupport,
cx: Commodities,
u: Utility,
I: Intuition,
gt: GadTools,
rq:ReqTools,
frq:FileReq,
d:Dos,
arg:Arguments,
g:Graphics,
wb:Workbench,
ol:OberonLib,
ic:Icon,
conv:Conversions,
fs:FileSystem,
str:Strings,
y: SYSTEM;
CONST
pVers=40;
CONST verstring="$VER: WCC 4.01 by HDS 1994";
namstring="Workbench Colour Changer";
TYPE colarp=ARRAY 256,3 OF LONGINT;
VAR
PopKey:ARRAY 100 OF CHAR;
MyBrk :cx.CxObjPtr;
MyFil :cx.CxObjPtr;
MySnd :cx.CxObjPtr;
MyTrs :cx.CxObjPtr;
NwBrk :cx.NewBroker;
MsPrt :e.MsgPortPtr;
Quit,guiOn :BOOLEAN;
ChCol :BOOLEAN;
Err,cfc :LONGINT;
eMsg :e.APTR;
Msg :cx.CxMsgPtr;
MsTp :LONGSET;
MsId :LONGINT;
CxPri :LONGINT;
CxKey :ARRAY 254 OF CHAR;
CxPop :BOOLEAN;
Signal:LONGSET;
iVer:LONGINT;
VAR n:INTEGER;
ms:I.IntuiMessagePtr;
ok:BOOLEAN;
iad:I.GadgetPtr;
colcn,colar:colarp;
pfnam,iffnam,wbnam:ARRAY 256 OF CHAR;
cnt:LONGINT;
fl:fs.File;
exMsg:e.MessagePtr;
Dela,Cycl:LONGINT;
Prefsname:ARRAY 30 OF CHAR;
DoCh:BOOLEAN;
PROCEDURE GetToolTypes;
VAR This:d.ProcessPtr;
wbm:wb.WBStartupPtr;
sptr:e.STRPTR;
MyIcon:wb.DiskObjectPtr;
OCurrentDir:d.FileLockPtr;
nm:INTEGER;
ttstrg:ARRAY 256 OF CHAR;
BEGIN;
CxPri:=0;
CxKey:=verstring;
CxKey:="alt control w";
CxPop:=TRUE;
Dela:=1;Cycl:=10;
This:=y.VAL(d.ProcessPtr,ol.Me);
IF ol.wbStarted THEN
wbm:=ol.wbenchMsg;
OCurrentDir:=This.currentDir;
y.SETREG(0,d.CurrentDir(wbm.argList[0].lock));
MyIcon := ic.GetDiskObject(wbm.argList[0].name^);
y.SETREG(0,d.CurrentDir(OCurrentDir));
IF MyIcon#NIL THEN
sptr := ic.FindToolType(MyIcon.toolTypes,"DELAY");
IF sptr#NIL THEN IF conv.StringToInt(sptr^,Dela) THEN END;END;
sptr := ic.FindToolType(MyIcon.toolTypes,"CYCLE");
IF sptr#NIL THEN IF conv.StringToInt(sptr^,Cycl) THEN END;END;
sptr := ic.FindToolType(MyIcon.toolTypes,"CX_PRIORITY");
IF sptr#NIL THEN IF conv.StringToInt(sptr^,CxPri) THEN END;END;
sptr := ic.FindToolType(MyIcon.toolTypes,"CX_POPKEY");
IF sptr#NIL THEN COPY(sptr^,CxKey);END;
sptr := ic.FindToolType(MyIcon.toolTypes,"CX_POPUP");
IF sptr#NIL THEN COPY(sptr^,ttstrg);END;
str.Upper(ttstrg);
IF (ttstrg="FALSE")OR(ttstrg="NO") THEN CxPop:=FALSE;END;
ic.FreeDiskObject(MyIcon);
END;
ELSE
IF arg.NumArgs()>0 THEN
FOR nm:=1 TO arg.NumArgs() DO
arg.GetArg(nm,ttstrg);
IF ttstrg="QUIET"
THEN CxPop:=FALSE;
ELSE
IF ttstrg="CX_POPUP=NO"
THEN CxPop:=FALSE;
ELSE
COPY(ttstrg,pfnam);
END;
END;
END;
END;
END;
Cycl:=Cycl;
END GetToolTypes;
(* GUI Stuff *)
CONST
GDSave * = 0;
GDUse * = 1;
GDCancel * = 2;
GDEdit * = 3;
GDLoad * = 4;
mnOpen *=-2048;
mnSave *=-2016;
mnAbout *=-1984;
mnHide *=-1952;
mnQuit *=-1920;
mnInIFF *=-2047;
mnInWB *=-2015;
mnOutIFF *=-2046;
mnOutWB *=-2014;
mnStart *=-2045;
mnCycle *=-2013;
CONST
prjCNT = 5;
prjLeft = 25;
prjTop = 42;
prjWidth = 311;
prjHeight = 62;
VAR
Scr*: I.ScreenPtr;
ScrCols: INTEGER;
VisualInfo*: e.APTR;
prjWnd*: I.WindowPtr;
prjGList*: I.GadgetPtr;
prjGadgets*: ARRAY prjCNT OF I.GadgetPtr;
Project0Menus*: I.MenuPtr;
Font*: g.TextAttrPtr;
Attr*: g.TextAttr;
FontX, FontY: INTEGER;
OffX, OffY: INTEGER;
ctPrt:e.MsgPortPtr;
TYPE
Project0MArray = ARRAY 16 OF gt.NewMenu;
CONST
Project0NewMenu = Project0MArray (
gt.title, y.ADR ("Project"), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("Open..."), y.ADR ("O"), {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("Save..."), y.ADR ("S"), {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("About..."), y.ADR ("A"), {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("Hide"), y.ADR ("H"), {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("Quit"), y.ADR ("Q"), {}, y.VAL (LONGSET, 0), NIL,
gt.title, y.ADR ("Import"), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("IFF Pic..."), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("WB Prefs..."), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.title, y.ADR ("Export"), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("IFF Palette..."), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("WB Prefs..."), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.title, y.ADR ("Settings"), NIL, {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("Start delay..."), y.ADR ("S"), {}, y.VAL (LONGSET, 0), NIL,
gt.item, y.ADR ("Cycle delay..."), y.ADR ("C"), {}, y.VAL (LONGSET, 0), NIL,
gt.end, NIL, NIL, {}, LONGSET {}, NIL);
VAR
prjIText: ARRAY 1 OF I.IntuiText;
TYPE
prjGTypesArray = ARRAY prjCNT OF INTEGER;
CONST
prjGTypes = prjGTypesArray (
gt.buttonKind,
gt.buttonKind,
gt.buttonKind,
gt.buttonKind,
gt.buttonKind
);
TYPE
prjNGadArray = ARRAY prjCNT OF gt.NewGadget;
CONST
prjNGad = prjNGadArray (
8, 37, 71, 17, y.ADR ("Save"), NIL, GDSave, LONGSET {gt.placeTextIn} ,NIL, NIL,
158, 37, 71, 17, y.ADR ("Use"), NIL, GDUse, LONGSET {gt.placeTextIn} ,NIL, NIL,
233, 37, 71, 17, y.ADR ("Cancel"), NIL, GDCancel, LONGSET {gt.placeTextIn} ,NIL, NIL,
233, 12, 71, 17, y.ADR ("Edit"), NIL, GDEdit, LONGSET {gt.placeTextIn} ,NIL, NIL,
83, 37, 71, 17, y.ADR ("Load"), NIL, GDLoad, LONGSET {gt.placeTextIn} ,NIL, NIL
);
TYPE
prjGTagsArray = ARRAY 5 OF u.Tag;
CONST
prjGTags = prjGTagsArray (
u.done,
u.done,
u.done,
u.done,
u.done
);
PROCEDURE ComputeX (value: INTEGER): INTEGER;
BEGIN
RETURN ((FontX * value) + 4 ) DIV 8;
END ComputeX;
PROCEDURE ComputeY (value: INTEGER): INTEGER;
BEGIN
RETURN ((FontY * value) + 4 ) DIV 8;
END ComputeY;
PROCEDURE ComputeFont (width, height: INTEGER);
BEGIN
Font := y. ADR (Attr);
Font^.name := Scr^.rastPort.font^.message.node.name;
FontY := Scr^.rastPort.font^.ySize;
Font^.ySize := FontY;
(* FontX := Scr^.rastPort.font^.xSize;
*)
FontX:=g.TextLength(y.ADR(Scr^.rastPort),"ABCDEFHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789.",64) DIV 64;
OffX := Scr^.wBorLeft;
OffY := Scr^.rastPort.txHeight + Scr^.wBorTop + 1;
IF (width # 0) AND (height # 0) AND
(ComputeX (width) + OffX + Scr^.wBorRight > Scr^.width) OR
(ComputeY (height) + OffY + Scr^.wBorBottom > Scr^.height) THEN
Font^.name := y.ADR ("topaz.font");
Font^.ySize := 8;
FontY := Font^.ySize;
FontX := Font^.ySize;
END;
END ComputeFont;
PROCEDURE SetupScreen* (): INTEGER;
BEGIN
Scr := I.LockPubScreen (NIL); IF Scr = NIL THEN RETURN 1 END;
ComputeFont (0, 0);
VisualInfo := gt.GetVisualInfo (Scr, u.done);
IF VisualInfo = NIL THEN RETURN 2 END;
RETURN 0;
END SetupScreen;
PROCEDURE CloseDownScreen*;
BEGIN
IF VisualInfo # NIL THEN
gt.FreeVisualInfo (VisualInfo);
VisualInfo := NIL;
END;
IF Scr # NIL THEN
I.UnlockPubScreen (NIL, Scr);
Scr := NIL;
END;
END CloseDownScreen;
PROCEDURE prjRender*;
BEGIN
prjIText[0].iText := y.ADR (namstring);
prjIText[0].iTextFont := Font;
prjIText[0].frontPen := 1;
prjIText[0].backPen := 0;
prjIText[0].drawMode := g.jam1+SHORTSET {};
prjIText[0].leftEdge := OffX + ComputeX (116) - (I.IntuiTextLength (prjIText[0]) DIV 2);
prjIText[0].topEdge := OffY + ComputeY (20) - (Font^.ySize DIV 2);
prjIText[0].nextText := NIL;
I.PrintIText (prjWnd^.rPort, prjIText[0], 0, 0);
gt.DrawBevelBox(prjWnd^.rPort, OffX + ComputeX (8),
OffY + ComputeY (12),
ComputeX (221),
ComputeY (17),
gt.visualInfo, VisualInfo, gt.bbRecessed, I.LTRUE, u.done);
END prjRender;
PROCEDURE OpenprjWindow* (): INTEGER;
TYPE
TagArrayPtr = UNTRACED POINTER TO ARRAY MAX (INTEGER) OF u.TagItem;
VAR
ng: gt.NewGadget;
gad: I.GadgetPtr;
help: TagArrayPtr;
lc, tc, lvc, offx, offy: INTEGER;
wleft, wtop, ww, wh: INTEGER;
BEGIN
wleft := prjLeft; wtop := prjTop;
ComputeFont (prjWidth, prjHeight);
ww := ComputeX (prjWidth);
wh := ComputeY (prjHeight);
IF wleft + ww + OffX + Scr^.wBorRight > Scr^.width THEN
wleft := Scr^.width - ww;
END;
IF wtop + wh + OffY + Scr^.wBorBottom > Scr^.height THEN
wtop := Scr^.height - wh;
END;
Project0Menus := gt.CreateMenus (Project0NewMenu,gt.fullMenu,I.LTRUE, u.done);
IF Project0Menus = NIL THEN RETURN 3 END;
IF NOT gt.LayoutMenus (Project0Menus, VisualInfo,gt.mnNewLookMenus,I.LTRUE, u.done) THEN RETURN 4 END;
gad := gt.CreateContext (prjGList);
IF gad = NIL THEN RETURN 1 END;
lc := 0; tc := 0; lvc := 0;
WHILE lc < prjCNT DO
ng := prjNGad[lc];
ng.visualInfo := VisualInfo;
ng.textAttr := Font;
ng.leftEdge := OffX + ComputeX (ng.leftEdge);
ng.topEdge := OffY + ComputeY (ng.topEdge);
ng.width := ComputeX (ng.width);
ng.height := ComputeY (ng.height);
gad := gt.CreateGadget (prjGTypes[lc], gad, ng, u.done );
IF gad = NIL THEN RETURN 2 END;
prjGadgets[lc] := gad;
WHILE prjGTags[tc] # u.done DO INC (tc, 2) END;
INC (tc);
INC (lc);
END; (* WHILE *)
prjWnd := I.OpenWindowTagsA ( NIL,
I.waLeft, wleft,
I.waTop, wtop,
I.waWidth, ww + OffX + Scr^.wBorRight,
I.waHeight, wh + OffY + Scr^.wBorBottom,
I.waIDCMP, gt.buttonIDCMP+LONGSET {I.menuPick,I.closeWindow,I.refreshWindow},
I.waFlags, LONGSET {I.windowDrag,I.windowDepth,I.activate},
I.waGadgets, prjGList,
I.waTitle, y.ADR ("WCC by HDS 1994"),
I.waScreenTitle, y.ADR ("Workbench Screen"),
I.waPubScreen, Scr,
I.waAutoAdjust, I.LTRUE,
I.waNewLookMenus, I.LTRUE,
u.done);
IF prjWnd = NIL THEN RETURN 20 END;
IF NOT I.SetMenuStrip (prjWnd, Project0Menus^) THEN RETURN 5 END;
gt.RefreshWindow (prjWnd, NIL);
prjRender;
RETURN 0;
END OpenprjWindow;
PROCEDURE CloseprjWindow*;
BEGIN
IF prjWnd # NIL THEN
I.CloseWindow (prjWnd);
prjWnd := NIL;
END;
IF prjGList # NIL THEN
gt.FreeGadgets (prjGList);
prjGList := NIL;
END;
END CloseprjWindow;
(* Colour Set/Load/Save *)
(*
PROCEDURE ReadCols;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;
BEGIN;
scr:=I.LockPubScreen("Workbench");
m:=scr.bitMap.depth;
k:=1;FOR l:=1 TO m DO k:=k*2;END;
FOR m:=0 TO k-1 DO
colar[m]:=g.GetRGB4(scr.viewPort.colorMap,m);END;
I.UnlockPubScreen(NIL,scr);
END ReadCols;
PROCEDURE SetCols;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;
BEGIN;
scr:=I.LockPubScreen("Workbench");
m:=scr.bitMap.depth;
k:=1;FOR l:=1 TO m DO k:=k*2;END;
g.LoadRGB4(y.ADR(scr.viewPort),colar^,k);
I.UnlockPubScreen(NIL,scr);
END SetCols;
*)
PROCEDURE ReadCols4;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;li,lb:LONGINT;
BEGIN;
scr:=I.LockPubScreen("Workbench");
FOR m:=0 TO ScrCols-1 DO
li:=g.GetRGB4(scr.viewPort.colorMap,m);
lb:=li MOD 32;li:=li DIV 32;
colar[m,0]:=SHORT(lb);
lb:=li MOD 32;li:=li DIV 32;
colar[m,1]:=SHORT(lb);
lb:=li MOD 32;li:=li DIV 32;
colar[m,2]:=SHORT(lb);
END;
I.UnlockPubScreen(NIL,scr);
END ReadCols4;
PROCEDURE ReadCols32;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;li,lb:LONGINT;
ar:ARRAY 3 OF LONGINT;
BEGIN;
scr:=I.LockPubScreen("Workbench");
FOR m:=0 TO ScrCols-1 DO
g.GetRGB32(scr.viewPort.colorMap,m,1,ar);
colar[m,0]:=ar[0];
colar[m,1]:=ar[1];
colar[m,2]:=ar[2];
END;
I.UnlockPubScreen(NIL,scr);
END ReadCols32;
PROCEDURE SetCols4;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;
BEGIN;
scr:=I.LockPubScreen("Workbench");
FOR l:=0 TO ScrCols-1 DO
g.SetRGB4(y.ADR(scr.viewPort),l,SHORT(colar[l,0]),SHORT(colar[l,1]),SHORT(colar[l,2]));
END;
I.UnlockPubScreen(NIL,scr);
END SetCols4;
PROCEDURE SetCols32;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;c1,c2,c3:LONGINT;
BEGIN;
scr:=I.LockPubScreen("Workbench");
FOR l:=0 TO ScrCols-1 DO
c1:=colar[l,0];
c2:=colar[l,1];
c3:=colar[l,2];
g.SetRGB32(y.ADR(scr.viewPort),l,c1,c2,c3);
END;
I.UnlockPubScreen(NIL,scr);
END SetCols32;
PROCEDURE SetCols;
BEGIN;
IF iVer<39 THEN
SetCols4;
ELSE
SetCols32;
END;
END SetCols;
PROCEDURE ReadCols;
BEGIN;
IF iVer<39 THEN
ReadCols4;
ELSE
ReadCols32;
END;
END ReadCols;
PROCEDURE ReadColsCn;
BEGIN;
ReadCols;
colcn:=colar;
END ReadColsCn;
PROCEDURE SetColsCn;
BEGIN;
colar:=colcn;
SetCols;
END SetColsCn;
(*
PROCEDURE ReadColsCn;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;
BEGIN;
scr:=I.LockPubScreen("Workbench");
m:=scr.bitMap.depth;
k:=1;FOR l:=1 TO m DO k:=k*2;END;
FOR m:=0 TO k-1 DO
colcn[m]:=g.GetRGB4(scr.viewPort.colorMap,m);END;
I.UnlockPubScreen(NIL,scr);
END ReadColsCn;
PROCEDURE SetColsCn;
VAR m,k,l:INTEGER;scr:I.ScreenPtr;
BEGIN;
scr:=I.LockPubScreen("Workbench");
m:=scr.bitMap.depth;
k:=1;FOR l:=1 TO m DO k:=k*2;END;
g.LoadRGB4(y.ADR(scr.viewPort),colcn^ ,k);
I.UnlockPubScreen(NIL,scr);
END SetColsCn;
*)
PROCEDURE LoadCols;
VAR m:INTEGER;
c1:CHAR;li:LONGINT;
BEGIN;
ok:=TRUE;
ok:=fs.Open(fl,"ENVARC:wcc.prefs",FALSE);
IF ok THEN
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#pVers THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#iVer THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(colar),y.SIZE(colar));
IF fs.Close(fl) THEN END;
IF ok THEN SetCols;END;
END;
IF ~ok THEN ReadCols;END;
END LoadCols;
PROCEDURE LoadColsFr;
VAR m:INTEGER;
c1:CHAR;li:LONGINT;
BEGIN;
ok:=TRUE;
ok:=fs.Open(fl,pfnam,FALSE);
IF ok THEN
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#pVers THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#iVer THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(colar),y.SIZE(colar));
IF fs.Close(fl) THEN END;
END;
IF ~ok THEN ReadCols;END;
END LoadColsFr;
PROCEDURE LoadColsAs;
VAR m:INTEGER;
ok:BOOLEAN;li:LONGINT;
BEGIN;
IF frq.FileReqWin("Load WCC prefs file",pfnam,prjWnd) THEN
ok:=TRUE;
ok:=fs.Open(fl,pfnam,FALSE);
IF ok THEN
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#pVers THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#iVer THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(colar),y.SIZE(colar));
IF fs.Close(fl) THEN END;
IF ok THEN SetCols;END;
END;
IF ~ok THEN ReadCols;END;
END;
END LoadColsAs;
PROCEDURE LoadColsOn;
VAR m:INTEGER;
ok:BOOLEAN;li:LONGINT;
BEGIN;
ok:=TRUE;
ok:=fs.Open(fl,pfnam,FALSE);
IF ok THEN
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#pVers THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(li),y.SIZE(li));
IF li#iVer THEN ok:=FALSE;END;
ok:=ok AND fs.ReadBlock(fl,y.ADR(colar),y.SIZE(colar));
IF fs.Close(fl) THEN END;
IF ok THEN SetCols;END;
END;
IF ~ok THEN ReadCols;END;
END LoadColsOn;
PROCEDURE UseCols;
VAR li:LONGINT;
BEGIN;
ReadCols;
IF fs.Open(fl,"ENV:wcc.prefs",TRUE) THEN
li:=pVers;IF fs.WriteBlock(fl,y.ADR(li),y.SIZE(li)) THEN END;
li:=iVer;IF fs.WriteBlock(fl,y.ADR(li),y.SIZE(li)) THEN END;
IF fs.WriteBlock(fl,y.ADR(colar),y.SIZE(colar)) THEN END;
IF fs.Close(fl) THEN END;
END;
END UseCols;
PROCEDURE SaveCols;
VAR li:LONGINT;
BEGIN;
ReadCols;
IF fs.Open(fl,"ENVARC:wcc.prefs",TRUE) THEN
li:=pVers;IF fs.WriteBlock(fl,y.ADR(li),y.SIZE(li)) THEN END;
li:=iVer;IF fs.WriteBlock(fl,y.ADR(li),y.SIZE(li)) THEN END;
IF fs.WriteBlock(fl,y.ADR(colar),y.SIZE(colar)) THEN END;
IF fs.Close(fl) THEN END;
UseCols;
END;
END SaveCols;
PROCEDURE SaveColsAs;
VAR li:LONGINT;
BEGIN;
IF frq.FileReqWin("Save WCC prefs file",pfnam,prjWnd) THEN
ReadCols;
IF fs.Open(fl,pfnam,TRUE) THEN
li:=pVers;IF fs.WriteBlock(fl,y.ADR(li),y.SIZE(li)) THEN END;
li:=iVer;IF fs.WriteBlock(fl,y.ADR(li),y.SIZE(li)) THEN END;
IF fs.WriteBlock(fl,y.ADR(colar),y.SIZE(colar)) THEN END;
IF fs.Close(fl) THEN END;
UseCols;
END;
END;
END SaveColsAs;
PROCEDURE Disable;
BEGIN;
IF cx.ActivateCxObj(MyBrk,0)#0 THEN END;
ChCol:=FALSE;
END Disable;
PROCEDURE Enable;
BEGIN;
IF cx.ActivateCxObj(MyBrk,1)#0 THEN END;
ChCol:=TRUE;
END Enable;
PROCEDURE Init():BOOLEAN;
VAR ret:BOOLEAN;
BEGIN;
ret:=TRUE;
IF ret THEN
MsPrt:=e.CreateMsgPort();
IF MsPrt=NIL THEN ret:=FALSE;END;
IF ret THEN
NwBrk.version:=cx.nbVersion;
NwBrk.name:=y.ADR("WCC");
NwBrk.title:=y.ADR("WCC 4.0 by HDS");
NwBrk.descr:=y.ADR("Workbench Colour Changer");
NwBrk.unique:=SET{0,1};
NwBrk.flags:=SET{cx.showHide};
NwBrk.pri:=SHORT(SHORT(CxPri));
NwBrk.port:=MsPrt;
NwBrk.reservedChannel:=0;
MyBrk:=cx.CxBroker(NwBrk,Err);
IF Err#0 THEN ret:=FALSE;END;
IF ret THEN
MyFil:=cx.CxFilter(y.ADR(CxKey));
MySnd:=cx.CxSender(MsPrt,cx.cxmIEvent);
MyTrs:=cx.CxTranslate(NIL);
IF cx.CxObjError(MyBrk)#LONGSET{} THEN ret:=FALSE;END;
IF cx.CxObjError(MyFil)#LONGSET{} THEN ret:=FALSE;END;
IF cx.CxObjError(MyTrs)#LONGSET{} THEN ret:=FALSE;END;
cx.AttachCxObj(MyBrk,MyFil);
cx.AttachCxObj(MyFil,MySnd);
cx.AttachCxObj(MyFil,MyTrs);
IF cx.CxObjError(MyBrk)#LONGSET{} THEN ret:=FALSE;END;
IF cx.CxObjError(MyFil)#LONGSET{} THEN ret:=FALSE;END;
IF cx.CxObjError(MyTrs)#LONGSET{} THEN ret:=FALSE;END;
IF cx.ActivateCxObj(MyBrk,1)#0 THEN ret:=FALSE;END;
IF MyFil=NIL THEN ret:=FALSE;END;
IF MySnd=NIL THEN ret:=FALSE;END;
IF MyTrs=NIL THEN ret:=FALSE;END;
IF cx.CxObjError(MyBrk)#LONGSET{} THEN ret:=FALSE;END;
IF cx.CxObjError(MyFil)#LONGSET{} THEN ret:=FALSE;END;
IF cx.CxObjError(MyTrs)#LONGSET{} THEN ret:=FALSE;END;
END;END;END;
RETURN (ret);
END Init;
PROCEDURE ShutDown;
BEGIN;
IF MyBrk#NIL THEN cx.DeleteCxObjAll(MyBrk);
REPEAT;UNTIL e.GetMsg(MsPrt)=NIL;END;
IF MsPrt#NIL THEN
e.DeleteMsgPort(MsPrt);END;
END ShutDown;
PROCEDURE CheckCx;
BEGIN;
IF MsPrt#NIL THEN
REPEAT;
eMsg:=e.GetMsg(MsPrt);
IF eMsg#NIL THEN
Msg:=y.VAL(cx.CxMsgPtr,eMsg);
MsTp:=cx.CxMsgType(Msg);
MsId:=cx.CxMsgID(Msg);
e.ReplyMsg(eMsg);
IF (MsTp=LONGSET{cx.cxmIEvent})AND(~guiOn) THEN
guiOn:=TRUE;;END;
IF MsTp=LONGSET{cx.cxmCommand} THEN
IF MsId=cx.cmdDisable THEN Disable;END;
IF (MsId=cx.cmdAppear)AND(~guiOn) THEN guiOn:=TRUE;END;
IF (MsId=cx.cmdDisappear)AND(guiOn) THEN guiOn:=FALSE;END;
IF MsId=cx.cmdEnable THEN Enable;END;
IF MsId=cx.cmdKill THEN Quit:=TRUE;guiOn:=FALSE;END;
IF MsId=cx.cmdUnique THEN Quit:=TRUE;END;
END;
END;
UNTIL eMsg=NIL;
END;
END CheckCx;
PROCEDURE ImportSys;
VAR buff:ARRAY 217 OF INTEGER;
fl:fs.File;
n,k,c:INTEGER;
BEGIN;
IF frq.FileReqWin("Load WB prefs file",wbnam,prjWnd) THEN
IF fs.Open(fl,wbnam,FALSE) THEN
FOR n:=0 TO 216 DO
IF fs.Read(fl,buff[n]) THEN END;
END;
IF fs.Close(fl) THEN END;
n:=0;c:=0;
WHILE c<8 DO
k:=buff[n+89];INC(c);
IF k>=0 THEN
IF k>3 THEN k:=ScrCols-8+k;END;
colar[k,0]:=buff[n+90] ;
colar[k,1]:=buff[n+91] ;
colar[k,2]:=buff[n+92] ;
colar[k,0]:=colar[k,0]+colar[k,0]*65536;
colar[k,1]:=colar[k,1]+colar[k,1]*65536;
colar[k,2]:=colar[k,2]+colar[k,2]*65536;
n:=n+4;
END;
END;
SetCols;
END;
END;
END ImportSys;
PROCEDURE ExportSys;
TYPE iar=ARRAY 2 OF INTEGER;
VAR buff:ARRAY 217 OF INTEGER;
fl:fs.File;
n,k,c:INTEGER;
l:LONGINT;
ia:iar;
fnam:ARRAY 256 OF CHAR;
BEGIN;
IF frq.FileReqWinSave("Save WB prefs file",wbnam,prjWnd) THEN
IF fs.Open(fl,wbnam,FALSE) THEN
FOR n:=0 TO 216 DO
IF fs.Read(fl,buff[n]) THEN END;
END;
IF fs.Close(fl) THEN END;
n:=0;c:=0;
WHILE c<8 DO
k:=buff[n+89];INC(c);
IF k>=0 THEN
IF k>3 THEN k:=ScrCols-8+k;END;
ia:=y.VAL(iar,colar[k,0]);
buff[n+90]:=ia[0];
ia:=y.VAL(iar,colar[k,1]);
buff[n+91]:=ia[0];
ia:=y.VAL(iar,colar[k,2]);
buff[n+92]:=ia[0];
n:=n+4;
END;
END;
IF fs.Open(fl,"ENV:Sys/palette.prefs",TRUE) THEN
FOR n:=0 TO 216 DO
IF fs.Write(fl,buff[n]) THEN END;
END;
IF fs.Close(fl) THEN END;
END;
END;
END;
END ExportSys;
PROCEDURE ImportIFF;
VAR fl:fs.File;
si1,si2,si3:SHORTINT;
li,num:LONGINT;
fnam:ARRAY 256 OF CHAR;
BEGIN;
IF frq.FileReqWin("Load IFF Palette file",iffnam,prjWnd) THEN
IF fs.Open(fl,iffnam,FALSE) THEN
WHILE (fl.status=fs.ok)AND(li#1129136464) DO
IF fs.Read(fl,li) THEN END;
END;
IF li=1129136464 THEN
IF fs.Read(fl,num) THEN END;
num:=num DIV 3;
IF num>ScrCols THEN num:=ScrCols;END;
FOR li:=0 TO num-1 DO
IF fs.Read(fl,si1) THEN END;
IF fs.Read(fl,si2) THEN END;
IF fs.Read(fl,si3) THEN END;
colar[li,0]:=si1+si1*256+si1*65536+si1*16777216;
colar[li,1]:=si2+si2*256+si3*65536+si3*16777216;
colar[li,2]:=si3+si3*256+si2*65536+si2*16777216;
END;
SetCols;
END;
IF fs.Close(fl) THEN END;
END;
END;
END ImportIFF;
PROCEDURE SetCycle;
VAR li:LONGINT;
BEGIN;
li:=Cycl;
IF rq.GetLong(li,"Set cycle delay (1/50 secs)",NIL,rq.Window,prjWnd,rq.glMax,1,rq.glMin,1000,rq.glWidth,ComputeX(250),u.done) THEN
Cycl:=li;
END;
END SetCycle;
PROCEDURE ExportIFF;
VAR fl:fs.File;
si1,si2,si3:SHORTINT;
li,num:LONGINT;
fnam:ARRAY 256 OF CHAR;
BEGIN;
rq.vEZRequestTags("Sorry, not\nimplemented yet.","Uhh.",NIL,NIL,rq.Window,prjWnd,u.done);
END ExportIFF;
PROCEDURE GUI;
BEGIN;
ReadColsCn;
IF SetupScreen()=0 THEN
IF OpenprjWindow()=0 THEN
n:=20;
REPEAT;
CheckCx;
ms:=gt.GetIMsg(prjWnd.userPort);
IF ms#NIL THEN
n:=-1;
iad:=ms.iAddress;
IF I.gadgetUp IN ms.class THEN
n:=iad.gadgetID;
IF n=GDEdit THEN
IF rq.PaletteRequest("Change Colors...",NIL,u.done)#0 THEN END;END;
IF n=GDLoad THEN LoadCols;END;
END;
IF I.menuPick IN ms.class THEN
IF ms.code=mnQuit THEN Quit:=TRUE;guiOn:=FALSE;END;
IF ms.code=mnOpen THEN LoadColsAs;END;
IF ms.code=mnSave THEN SaveColsAs;END;
IF ms.code=mnHide THEN guiOn:=FALSE;END;
IF ms.code=mnInWB THEN ImportSys;END;
IF ms.code=mnInIFF THEN ImportIFF;END;
IF ms.code=mnOutWB THEN ExportSys;END;
IF ms.code=mnOutIFF THEN ExportIFF;END;
IF ms.code=mnCycle THEN SetCycle;END;
IF ms.code=mnAbout THEN
rq.vEZRequestTags("Workbench Colour Changer\n""Version 4.01",
"Ok",NIL,NIL,rq.Window,prjWnd,
rq.ezReqTitle,y.ADR("WCC 4.01"),u.done);
END;
END;
e.ReplyMsg(ms);
ELSE
d.Delay(10);
END;
UNTIL (n=GDSave)OR(n=GDCancel)OR(n=GDUse)OR(~guiOn);
IF n=GDSave THEN SaveCols;END;
IF n=GDCancel THEN SetColsCn;END;
IF n=GDUse THEN UseCols;END;
guiOn:=FALSE;
CloseprjWindow;END;
CloseDownScreen;END;
END GUI;
PROCEDURE InitS;
VAR m,l:INTEGER;
scr:I.ScreenPtr;
BEGIN;
scr:=I.LockPubScreen("Workbench");
m:=scr.bitMap.depth;
ScrCols:=1;
FOR l:=1 TO m DO ScrCols:=ScrCols*2;END;
I.UnlockPubScreen(NIL,scr);
END InitS;
BEGIN;
InitS;
iVer:=I.int.libNode.version;
wbnam:="ENV:Sys/palette.prefs";
iffnam:=":";
pfnam:="ENVARC:wcc.prefs";
GetToolTypes;
guiOn:=CxPop;
cfc:=Cycl * 2;
cnt:=Dela * 2;
IF Init() THEN
ChCol:=TRUE;
Enable;
CheckCx;
Quit:=FALSE;
DoCh:=TRUE;
LoadColsFr;
REPEAT;
IF (cnt<1)AND(ChCol) THEN IF ok THEN SetCols;END;cnt:=cfc;END;
DEC(cnt);
d.Delay(25);
CheckCx;
IF guiOn THEN GUI;END;
UNTIL Quit;
END;
CLOSE
ShutDown;
END WCC4.